package com.hzhr.iot.meterplan.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.meterplan.controller.base.BaseController;
import com.hzhr.iot.meterplan.model.meterPlan.MeterPlanGetModel;
import com.hzhr.iot.meterplan.model.meterPlan_workOrder.MeterPlan_workOrderGetModel;
import com.hzhr.iot.meterplan.model.meterPlan_workOrder.MeterPlan_workOrderModel;
import com.hzhr.iot.meterplan.service.MeterPlanService;
import com.hzhr.iot.meterplan.service.MeterPlan_WorkOrderService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "MeterPlan_WorkOrder", description = "抄表计划下的工单")
@RestController
@RequestMapping(value = "")
public class MeterPlan_WorkOrderController extends BaseController {
    @Autowired
    MeterPlan_WorkOrderService meterPlan_workOrderService;

    //region /meter-plans/{meterPlanId}/work-orders GET
    //region swagger响应码 : get
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : get
    @ApiOperation(value="查询抄表计划下的状态为“待抄表”抄表工单(无分页)", notes="查询抄表计划下的状态为“待抄表”抄表工单(无分页)  \n1.查询抄表计划，如果抄表计划不存在，抛出异常“抄表计划不存在”  \n2.查询该抄表计划下的状态为“待抄表”或“待审核”的抄表工单，  \n 然后根据抄表工单所对应的采集设备，找到筛选条件所对应的那一天的第一条采集数据或者该设备的最近一条的采集数据进行组合  \n3.返回信息  \n",produces = "application/json")
    //endregion
    //region swagger参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "meterPlanId", value = "抄表计划id", required = true, dataType = "string", paramType = "path"),
            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件：where MeterPlan_workOrderModel.id = #{equal_id}", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "like_gasUserCode", value = "筛选条件：where MeterPlan_workOrderModel.des like % + #{like_gasUserCode} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_gsaUserName", value = "筛选条件：where MeterPlan_workOrderModel.typeId like % + #{like_gsaUserName} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_gasUserAddress", value = "筛选条件：where MeterPlan_workOrderModel.gasUserAddress  % + #{like_gasUserAddress} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_meterNo", value = "筛选条件：where MeterPlan_workOrderModel.meterNo  % + #{like_meterNo} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "equal_collectTime", value = "筛选条件：where MeterPlan_workOrderModel.collectTime = #{equal_collectTime}", required = false, dataType = "string", paramType = "query"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局", defaultValue = "0", required = false, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件：where MeterPlan_workOrderModel.id = id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_like_gasUserCode", value = "筛选条件：where MeterPlan_workOrderModel.des like % + #{_like_gasUserCode} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_gsaUserName", value = "筛选条件：where MeterPlan_workOrderModel.typeId like % + #{_like_gsaUserName} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_gasUserAddress", value = "筛选条件：where MeterPlan_workOrderModel.gasUserAddress  % + #{_like_gasUserAddress} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_meterNo", value = "筛选条件：where MeterPlan_workOrderModel.meterNo  % + #{_like_meterNo} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_equal_collectTime", value = "筛选条件：where MeterPlan_workOrderModel.collectTime = #{_equal_collectTime}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/meter-plans/{meterPlanId}/work-orders", method = RequestMethod.GET)
    //endregion
    @Author
    public ResponseEntity<MeterPlan_workOrderGetModel> get(@PathVariable("meterPlanId")String meterPlanId,
                                                           @RequestParam @ApiIgnore Map<String, Object> query) throws ServiceException {
        MeterPlan_workOrderGetModel responseBody = meterPlan_workOrderService.get(initHeader(),meterPlanId,query);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
}




